package org.example.l2;

import java.util.*;

/**
 * {@link com.jayway.jsonpath.spi.cache.LRUCache}
 */
public class LRUCache2
        extends LinkedHashMap<Integer, Integer> {
    private int capacity;

    public LRUCache2(int capacity) {
        super(capacity, 0.75F, true);
        this.capacity = capacity;
    }

    @Override
    public Integer get(Object key) {
        return getOrDefault(key, -1);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
        return size() > capacity;
    }
}